package com.kgcx.organization.controller;

import com.kgcx.common.bean.RequestData;
import com.kgcx.common.bean.ReturnData;
import com.kgcx.common.controller.BaseController;
import com.kgcx.organization.domain.Company;
import com.kgcx.organization.service.CompanyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(description = "公司接口", tags = "公司接口")
@RestController
@RequestMapping("company")
public class CompanyController extends BaseController {
    @Autowired
    private CompanyService companyService;

    /**
     * 专给监管平台提供查询
     */
    @ApiOperation(value = "查询公司", httpMethod = "GET", notes = "这是用来查询公司的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "kid", value = "公司ID", required = true, paramType = "query", dataType = "String", dataTypeClass = Long.class),
    })
    @GetMapping("getCompany")
    public ReturnData<Company> getCompany() {
        RequestData requestData = this.getRequestData();
        Company company = companyService.getCompany(requestData.getLong("kid"));
        return new ReturnData<>(company);
    }

    @ApiOperation(value = "查询公司", httpMethod = "GET", notes = "这是用来查询公司的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "页容量", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "orderBy", value = "排序", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "cityId", value = "城市id", required = false, paramType = "query", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "serviceNameLike", value = "名称", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "serviceNoLike", value = "公司编码,服务机构代码", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "managerNameLike", value = "管理人", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "managerPhoneLike", value = "管理人电话", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "createTime", value = "录入时间", required = false, paramType = "query", dataType = "Long", dataTypeClass = Long.class),
    })
    @GetMapping("getCompanyList")
    public ReturnData<List<Company>> getCompanyList() {
        RequestData requestData = this.getRequestData();
        List<Company> companyList = companyService.getCompanyList(requestData);
        return new ReturnData<>(companyList);
    }

    @ApiOperation(value = "新增公司", httpMethod = "POST", notes = "这是用来新增公司的接口")
    @PostMapping("addCompany")
    public ReturnData addCompany(@RequestBody Company company) {
        companyService.addCompany(company);
        return new ReturnData();
    }

    @ApiOperation(value = "修改公司", httpMethod = "POST", notes = "这是用来修改公司的接口")
    @PostMapping("updateCompany")
    public ReturnData updateCompany(@RequestBody Company company) {
        companyService.updateCompany(company);
        return new ReturnData();
    }

    @ApiOperation(value = "删除公司", httpMethod = "POST", notes = "这是用来删除公司的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "kid", value = "用户ID", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class)
    })
    @PostMapping("removeCompany")
    public ReturnData removeCompany(@RequestParam Long kid) {
        companyService.removeCompany(kid);
        return new ReturnData();
    }
}
